﻿using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevTeam;
using System;
using System.Data;


namespace ConfExpert.Forms.Sistem.Conversion
{
    public partial class SiparisGir : XPopupForm
    {
        public int BrandId { get; set; }
        public int SezonId { get; set; }
        public string OrderRef { get; set; }

        public SiparisGir()
        {
            InitializeComponent();
        }

        private void StokTransfer_Load(object sender, EventArgs e)
        {
            this.Text = "Ayrım";
            this.btnSiparisGir.Text = "Tamamla";
            chkIdle.Visible = true;

            btnSiparisGir.Click += new EventHandler(btnTransfer_Click);
            chkIdle.CheckedChanged += new EventHandler(chkIdle_CheckedChanged);

            GetDetails("SODetay", "GetOrderRefforAksesuar");

            gleOrderRef.Properties.Assign(GetIntellisensedRI(ds.SODetay));
            gleOrderRef.Properties.ProcessNewValue += new ProcessNewValueEventHandler(ri_ProcessNewValue2);
            gleOrderRef.Properties.View.Columns["BrandId"].ColumnEdit = RI(Rp.Brand);
            gleOrderRef.Properties.View.Columns["SezonId"].ColumnEdit = RI(Rp.Sezon);
            gleOrderRef.EditValueChanged += new EventHandler(gleOrderRef_EditValueChanged);

            gleBrand.Properties.Assign(RI(Rp.Brand));
            gleSezon.Properties.Assign(RI(Rp.Sezon));


            cmbTercih.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
            cmbTercih.SelectedIndexChanged += new EventHandler(cmbTercih_SelectedIndexChanged);
            this.Shown += new EventHandler(Transfer_Shown);
        }

        void gleOrderRef_EditValueChanged(object sender, EventArgs e)
        {
            if (gleOrderRef.Properties.View.GetFocusedRow() != null)
            {		 
                DataRow dr = ((DataRowView)gleOrderRef.Properties.View.GetFocusedRow()).Row;
                gleBrand.EditValue = intParse(dr["BrandId"]);
                gleSezon.EditValue = intParse(dr["SezonId"]);
            }
        }

        void cmbTercih_SelectedIndexChanged(object sender, EventArgs e)
        {
            deTill.Visible = cmbTercih.SelectedIndex == 2;
            cmbSure.Visible = cmbTercih.SelectedIndex == 1;
        }

        void Transfer_Shown(object sender, EventArgs e)
        {
            gleOrderRef.Focus();
        }


        void chkIdle_CheckedChanged(object sender, EventArgs e)
        {
            gleOrderRef.Enabled = !chkIdle.Checked;
            if (chkIdle.Checked)
                gleOrderRef.EditValue = null;
        }

        void btnTransfer_Click(object sender, EventArgs e)
        {
            string name = gleOrderRef.Text;
            if (name.IsNullOrWhiteSpace() && !chkIdle.Checked)
            {
                XtraMessageBox.Show("OrderRef boş olamaz!");
                return;
            }
            if (intParse(gleBrand.EditValue) == 0)
            {
                XtraMessageBox.Show("Marka boş olamaz!");
                return;
            }
            if (intParse(gleSezon.EditValue) == 0)
            {
                XtraMessageBox.Show("Sezon boş olamaz!");
                return;
            }

            BrandId = gleBrand.EditValue.ToInt();
            SezonId = gleSezon.EditValue.ToInt();
            OrderRef = gleOrderRef.Text;

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }
    }
}